package DMSXL._2024.BinaryTrees;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class findBottomLeftValue {
    public static void main(String[] args) {
        Integer[] nums = {1,2,3,};
        TreeNode root = CreateTree.createBinaryTree(nums,0);
        System.out.println();
    }
    List<List<Integer>> result = new ArrayList<>();
    public int findBottomLeftValue(TreeNode root) {

        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()){
            int k = queue.size();
            List<Integer> temp = new ArrayList<>();
            for (int i = 0; i < k; i++) {
                TreeNode cur = queue.poll();
                temp.add(cur.val);
                if(cur.left != null){
                    queue.offer(cur.left);
                }
                if(cur.right != null){
                    queue.offer((cur.right));
                }
            }
            result.add(temp);
        }
        System.out.println(result);
        return result.get(result.size() - 1).get(0);
    }
}
